package com.zhejiangzhengyuan.municipal_common.utils;

import java.util.Base64;

/**
 * @author ZhouXiang
 * @since on 2019/12/27
 */
public class BaseUtil {

  /** base64加密过后的值转为16位的字符串 */
  public static String get16BinaryBy(String value) {
    if (value == null || value.equals("")) {
      return null;
    }
    byte[] decoded = Base64.getDecoder().decode(value);
    return toHex(decoded);
  }

  private static String toHex(byte[] data) {
    StringBuilder stringBuffer = new StringBuilder(data.length * 2);
    for (byte datum : data) {
      stringBuffer.append(DIGITS[(datum >>> 4) & 0x0F]);
      stringBuffer.append(DIGITS[datum & 0x0F]);
    }
    return stringBuffer.toString();
  }

  private static final char[] DIGITS = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  };

  /** 16进制转10进制 */
  public static String byte16to10byte(String value) {
    int anInt = Integer.parseInt(value, 16);
    return anInt + "";
  }
}
